package listener;

import javax.swing.JComponent;

import protocal.DataPackage;
import protocal.DataPackage.MessageType;
import adapter.MessageAdapter;
import data.DataMessageList;

public class ChatListener extends Listener {
	
	private JComponent jComponent;
	
	private Listener listener;
	private MessageAdapter messageAdapter;
	
	
	

	public ChatListener(JComponent jComponent,Listener listener) {
		this.jComponent = jComponent;
		this.listener = listener;
		messageAdapter = new MessageAdapter(this.jComponent, DataMessageList.getInstance().getDataMessages());
	}



	@Override
	public void listen(DataPackage dataPackage) {
		listener.listen(dataPackage);
		messageListen(dataPackage);
		shakeListen(dataPackage);

	}
	
	private void messageListen(DataPackage dataPackage){
		if (dataPackage.getMessageType()==MessageType.MESSAGE) {
			messageAdapter.adapter(dataPackage);
		}
	}
	
	private void shakeListen(DataPackage dataPackage){
		if (dataPackage.getMessageType()==MessageType.SHAKE) {
			messageAdapter.adapter(dataPackage);
		}
	}

}
